using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
using System.Configuration;
using PCSComUtils.DataAccess;
using PCSComUtils.PCSExc;
using PCSComUtils.Common;
using System.Runtime.InteropServices;
namespace PCSComProduction.ShopFloorControl.DS
{
	/// <summary>
	/// 
	/// 
	/// </summary>
	public class PRO_WOScheduleDetailDS 
	{
		public PRO_WOScheduleDetailDS()
		{
		}
		private const string THIS = "PCSComProduction.ShopFloorControl.DS.PRO_WOScheduleDetailDS";

	
		//**************************************************************************              
		///    <Description>
		///       This method uses to add data to PRO_WOScheduleDetail
		///    </Description>
		///    <Inputs>
		///        PRO_WOScheduleDetailVO       
		///    </Inputs>
		///    <Outputs>
		///       newly inserted primarkey value
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, May 31, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************


		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";
			 
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS =null;
			try
			{
				PRO_WOScheduleDetailVO objObject = (PRO_WOScheduleDetailVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);
				
				strSql=	"INSERT INTO PRO_WOScheduleDetail("
					+ PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD + ","
					+ PRO_WOScheduleDetailTable.STARTDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.ENDDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.COMMENTS_FLD + ","
					+ PRO_WOScheduleDetailTable.SHIFTID_FLD + ","
					+ PRO_WOScheduleDetailTable.TYPE_FLD + ","
					+ PRO_WOScheduleDetailTable.FUNCTIONID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOROUTINGID_FLD + ","
					+ PRO_WOScheduleDetailTable.WORKCENTERID_FLD + ")"
					+ "VALUES(?,?,?,?,?,?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD].Value = objObject.WOScheduleDetailID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.STARTDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.STARTDATETIME_FLD].Value = objObject.StartDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.ENDDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.ENDDATETIME_FLD].Value = objObject.EndDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.COMMENTS_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.COMMENTS_FLD].Value = objObject.Comments;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.SHIFTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.SHIFTID_FLD].Value = objObject.ShiftID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.SHIFTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.SHIFTID_FLD].Value = objObject.ShiftID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.TYPE_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.TYPE_FLD].Value = objObject.Type;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.FUNCTIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.FUNCTIONID_FLD].Value = objObject.FunctionID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.WORKCENTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.WORKCENTERID_FLD].Value = objObject.WorkCenterID;

				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	


		//**************************************************************************              
		///    <Description>
		///       This method uses to delete data from PRO_WOScheduleDetail
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       void
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql=	"DELETE " + PRO_WOScheduleDetailTable.TABLE_NAME + " WHERE  " + "WOScheduleMasterID" + "=" + pintID.ToString();
			OleDbConnection oconPCS=null;
			OleDbCommand ocmdPCS =null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
				ocmdPCS = null;

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}
			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
	
		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from PRO_WOScheduleDetail
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       PRO_WOScheduleDetailVO
		///    </Outputs>
		///    <Returns>
		///       PRO_WOScheduleDetailVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, May 31, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();
			
			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				strSql=	"SELECT "
					+ PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD + ","
					+ PRO_WOScheduleDetailTable.STARTDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.ENDDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.COMMENTS_FLD + ","
					+ PRO_WOScheduleDetailTable.SHIFTID_FLD + ","
					+ PRO_WOScheduleDetailTable.TYPE_FLD + ","
					+ PRO_WOScheduleDetailTable.FUNCTIONID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOROUTINGID_FLD + ","
					+ PRO_WOScheduleDetailTable.WORKCENTERID_FLD
					+ " FROM " + PRO_WOScheduleDetailTable.TABLE_NAME
					+" WHERE " + PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				PRO_WOScheduleDetailVO objObject = new PRO_WOScheduleDetailVO();

				while (odrPCS.Read())
				{ 
					objObject.WOScheduleMasterID = int.Parse(odrPCS[PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD].ToString().Trim());
					objObject.WOScheduleDetailID = int.Parse(odrPCS[PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD].ToString().Trim());
					objObject.StartDateTime = DateTime.Parse(odrPCS[PRO_WOScheduleDetailTable.STARTDATETIME_FLD].ToString().Trim());
					objObject.EndDateTime = DateTime.Parse(odrPCS[PRO_WOScheduleDetailTable.ENDDATETIME_FLD].ToString().Trim());
					objObject.Comments = odrPCS[PRO_WOScheduleDetailTable.COMMENTS_FLD].ToString().Trim();
					objObject.ShiftID = int.Parse(odrPCS[PRO_WOScheduleDetailTable.SHIFTID_FLD].ToString().Trim());
					objObject.Type = int.Parse(odrPCS[PRO_WOScheduleDetailTable.TYPE_FLD].ToString().Trim());
					objObject.FunctionID = int.Parse(odrPCS[PRO_WOScheduleDetailTable.FUNCTIONID_FLD].ToString().Trim());
					objObject.WORoutingID = int.Parse(odrPCS[PRO_WOScheduleDetailTable.WOROUTINGID_FLD].ToString().Trim());
					objObject.WorkCenterID = int.Parse(odrPCS[PRO_WOScheduleDetailTable.WORKCENTERID_FLD].ToString().Trim());
				}		
				return objObject;					
			}
			catch(OleDbException ex)
			{			
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			

			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to update data to PRO_WOScheduleDetail
		///    </Description>
		///    <Inputs>
		///       PRO_WOScheduleDetailVO       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			PRO_WOScheduleDetailVO objObject = (PRO_WOScheduleDetailVO) pobjObjecVO;
			

			//prepare value for parameters
			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql=	"UPDATE PRO_WOScheduleDetail SET "
					+ PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD + "=   ?" + ","
					+ PRO_WOScheduleDetailTable.STARTDATETIME_FLD + "=   ?" + ","
					+ PRO_WOScheduleDetailTable.ENDDATETIME_FLD + "=   ?" + ","
					+ PRO_WOScheduleDetailTable.COMMENTS_FLD + "=   ?" + ","
					+ PRO_WOScheduleDetailTable.SHIFTID_FLD + "=   ?" + ","
					+ PRO_WOScheduleDetailTable.WOROUTINGID_FLD + "=   ?" + ","
					+ PRO_WOScheduleDetailTable.WORKCENTERID_FLD + "=  ?"
					+" WHERE " + PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD].Value = objObject.WOScheduleDetailID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.STARTDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.STARTDATETIME_FLD].Value = objObject.StartDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.ENDDATETIME_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.ENDDATETIME_FLD].Value = objObject.EndDateTime;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.COMMENTS_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.COMMENTS_FLD].Value = objObject.Comments;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.SHIFTID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.SHIFTID_FLD].Value = objObject.ShiftID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.WOROUTINGID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.WOROUTINGID_FLD].Value = objObject.WORoutingID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.WORKCENTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.WORKCENTERID_FLD].Value = objObject.WorkCenterID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD].Value = objObject.WOScheduleMasterID;


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();	
			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from PRO_WOScheduleDetail
		///    </Description>
		///    <Inputs>
		///               
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, May 31, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = String.Empty;
				
				strSql=	"SELECT "
					+ PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD + ","
					+ PRO_WOScheduleDetailTable.STARTDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.ENDDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.COMMENTS_FLD + ","
					+ PRO_WOScheduleDetailTable.SHIFTID_FLD + ","
					+ PRO_WOScheduleDetailTable.TYPE_FLD + ","
					+ PRO_WOScheduleDetailTable.FUNCTIONID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOROUTINGID_FLD + ","
					+ PRO_WOScheduleDetailTable.WORKCENTERID_FLD
					+ " FROM " + PRO_WOScheduleDetailTable.TABLE_NAME;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,PRO_WOScheduleDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		/// <summary>
		/// List data of WOLine
		/// </summary>
		/// <param name="pintWOMasterID"></param>
		/// <param name="pintWODetailID"></param>
		/// <returns></returns>
		public DataSet ListData(int pintWOMasterID, int pintWODetailID)
		{
			const string METHOD_NAME = THIS + ".ListData()",
					  OPERATION = "Operation", FUNCTION = "FunctionCode", TYPE = "TypeCode", SHIFT = "Shift", WORKCENTER = "WorkCenter", 
					  INSIDE = "Inside", OUTSIDE = "Outside", TBL_MAS = " TABLE_MASTER", TBL_DET = " TABLE_DETAIL";
			const int IN = 0, OUT = 1;
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = "SELECT "
					+ TBL_DET + "." + PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD
					+ ",(SELECT " + PRO_WORoutingTable.STEP_FLD + " FROM " + PRO_WORoutingTable.TABLE_NAME + " WHERE " + PRO_WORoutingTable.TABLE_NAME + "." + PRO_WORoutingTable.WOROUTINGID_FLD + " = " + TBL_DET + "." + PRO_WOScheduleDetailTable.WOROUTINGID_FLD + ") as " + OPERATION
					+ ", CASE " + PRO_WORoutingTable.TYPE_FLD + " WHEN " + IN + " THEN '" + INSIDE + "' WHEN " + OUT + " THEN '" + OUTSIDE + "' END as " + TYPE
					+ ",(SELECT " + MST_FunctionTable.CODE_FLD + " FROM " + MST_FunctionTable.TABLE_NAME + " WHERE " + MST_FunctionTable.TABLE_NAME + "." + MST_FunctionTable.FUNCTIONID_FLD + " = " + TBL_DET + "." + PRO_WOScheduleDetailTable.FUNCTIONID_FLD + ") as " + FUNCTION
					+ ",(SELECT " + MST_WorkCenterTable.CODE_FLD + " FROM " + MST_WorkCenterTable.TABLE_NAME + " WHERE " + MST_WorkCenterTable.TABLE_NAME + "." + MST_WorkCenterTable.WORKCENTERID_FLD + " = " + TBL_DET + "." + PRO_WOScheduleDetailTable.WORKCENTERID_FLD + ") as " + WORKCENTER
					+ ",(SELECT " + PRO_ShiftTable.SHIFTDESC_FLD + " FROM " + PRO_ShiftTable.TABLE_NAME + " WHERE " + PRO_ShiftTable.TABLE_NAME + "." + PRO_ShiftTable.SHIFTID_FLD + " = " + TBL_DET + "." + PRO_WOScheduleDetailTable.SHIFTID_FLD + ") as " + SHIFT + ","
					+ PRO_WOScheduleDetailTable.STARTDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.ENDDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.COMMENTS_FLD + ","
					+ PRO_WOScheduleDetailTable.SHIFTID_FLD + ","
					+ PRO_WOScheduleDetailTable.TYPE_FLD + ","
					+ PRO_WOScheduleDetailTable.FUNCTIONID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOROUTINGID_FLD + ","
					+ PRO_WOScheduleDetailTable.WORKCENTERID_FLD
					+ " FROM " + PRO_WOScheduleDetailTable.TABLE_NAME + TBL_DET + " INNER JOIN " + PRO_WOScheduleMasterTable.TABLE_NAME + TBL_MAS + " ON " + TBL_DET + "." + PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD + " = " + TBL_MAS + "." + PRO_WOScheduleMasterTable.WOSCHEDULEMASTERID_FLD
					+ " WHERE "+ TBL_MAS + "." + PRO_WOScheduleMasterTable.WORKORDERMASTERID_FLD + " = " + pintWOMasterID + " AND " + TBL_MAS + "." + PRO_WOScheduleMasterTable.WORKORDERDETAILID_FLD + " = " + pintWODetailID;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,PRO_WOScheduleDetailTable.TABLE_NAME);

				return dstPCS;
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to update a DataSet
		///    </Description>
		///    <Inputs>
		///        DataSet       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Tuesday, May 31, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void UpdateDataSet(DataSet pData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS =null;
			OleDbCommandBuilder odcbPCS ;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				strSql=	"SELECT "
					+ PRO_WOScheduleDetailTable.WOSCHEDULEDETAILID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOSCHEDULEMASTERID_FLD + ","
					+ PRO_WOScheduleDetailTable.STARTDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.ENDDATETIME_FLD + ","
					+ PRO_WOScheduleDetailTable.COMMENTS_FLD + ","
					+ PRO_WOScheduleDetailTable.SHIFTID_FLD + ","
					+ PRO_WOScheduleDetailTable.TYPE_FLD + ","
					+ PRO_WOScheduleDetailTable.FUNCTIONID_FLD + ","
					+ PRO_WOScheduleDetailTable.WOROUTINGID_FLD + ","
					+ PRO_WOScheduleDetailTable.WORKCENTERID_FLD 
					+ "  FROM " + PRO_WOScheduleDetailTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pData.EnforceConstraints = false;
				odadPCS.Update(pData,PRO_WOScheduleDetailTable.TABLE_NAME);

			}
			catch(OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
																   
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);				
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{

					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);				
				}
				
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
				}
			}			

			catch(InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}

		}
		

		/// <summary>
		/// Get data information of Item in WOLine
		/// </summary>
		/// <param name="pintWOMasterID"></param>
		/// <param name="pintWODetailID"></param>
		/// <returns></returns>
		public DataRow GetItemOrderInfo(int pintWOMasterID, int pintWODetailID)
		{
			const string PART_NUMBER = "PartNumber", PART_NAME = "PartName", MODEL = "Model", UMCODE = "UMCode",
					  TOTALCOMPLETE = "TotalQuantity", TOTALSCARPT = "TotalScrap";
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS =null;
			OleDbCommand ocmdPCS = null;
			try 
			{
				string strSql = "SELECT "
					+ " (SELECT " + ITM_ProductTable.CODE_FLD + " FROM " + ITM_ProductTable.TABLE_NAME + " WHERE " + ITM_ProductTable.PRODUCTID_FLD + " = " + PRO_WorkOrderDetailTable.TABLE_NAME + "." + PRO_WorkOrderDetailTable.PRODUCTID_FLD+ ") as " + PART_NUMBER + ","
					+ " (SELECT " + ITM_ProductTable.DESCRIPTION_FLD + " FROM " + ITM_ProductTable.TABLE_NAME + " WHERE " + ITM_ProductTable.PRODUCTID_FLD + " = " + PRO_WorkOrderDetailTable.TABLE_NAME + "." + PRO_WorkOrderDetailTable.PRODUCTID_FLD+ ") as " + PART_NAME + ","
					+ " (SELECT " + ITM_ProductTable.REVISION_FLD + " FROM " + ITM_ProductTable.TABLE_NAME + " WHERE " + ITM_ProductTable.PRODUCTID_FLD + " = " + PRO_WorkOrderDetailTable.TABLE_NAME + "." + PRO_WorkOrderDetailTable.PRODUCTID_FLD+ ") as " + MODEL + ","
					+ " (SELECT " + MST_UnitOfMeasureTable.CODE_FLD + " FROM " + MST_UnitOfMeasureTable.TABLE_NAME + " WHERE " + MST_UnitOfMeasureTable.UNITOFMEASUREID_FLD + " = " + PRO_WorkOrderDetailTable.TABLE_NAME + "." + PRO_WorkOrderDetailTable.STOCKUMID_FLD+ ") as " + UMCODE + ","
					+ PRO_WorkOrderDetailTable.ORDERQUANTITY_FLD + ","
					+ PRO_WorkOrderDetailTable.STARTDATE_FLD + ","
					+ PRO_WorkOrderDetailTable.DUEDATE_FLD + ","
					+ " (SELECT SUM(" + PRO_WorkOrderCompletionTable.COMPLETEDQUANTITY_FLD + ") FROM " + PRO_WorkOrderCompletionTable.TABLE_NAME + " WHERE " + PRO_WorkOrderCompletionTable.WORKORDERMASTERID_FLD + " = " + pintWOMasterID + " And " + PRO_WorkOrderCompletionTable.WORKORDERDETAILID_FLD + " = " + pintWODetailID + ") as " + TOTALCOMPLETE + ","
					+ " (SELECT SUM(" + PRO_AOScrapDetailTable.SCRAPQUANTITY_FLD + ") FROM " + PRO_AOScrapDetailTable.TABLE_NAME + " WHERE " + PRO_AOScrapDetailTable.WORKORDERMASTERID_FLD + " = " + pintWOMasterID + " And " + PRO_AOScrapDetailTable.WORKORDERDETAILID_FLD + " = " + pintWODetailID + ") as " + TOTALSCARPT
					+ " FROM " + PRO_WorkOrderDetailTable.TABLE_NAME
					+ " WHERE " + PRO_WorkOrderDetailTable.WORKORDERMASTERID_FLD + " = " + pintWOMasterID + " AND " + PRO_WorkOrderDetailTable.WORKORDERDETAILID_FLD + " = " + pintWODetailID;
						
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();
				
				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS,PRO_WOScheduleDetailTable.TABLE_NAME);

				if (dstPCS.Tables[0].Rows[0][TOTALCOMPLETE].ToString() == string.Empty)
				{
					dstPCS.Tables[0].Rows[0][TOTALCOMPLETE] =0;
				}
				if (dstPCS.Tables[0].Rows[0][TOTALSCARPT].ToString() == string.Empty)
				{
					dstPCS.Tables[0].Rows[0][TOTALSCARPT] =0;
				}
				return dstPCS.Tables[0].Rows[0];
			}
			catch(OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME,ex);
			}			
			catch (Exception ex) 
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally 
			{
				if (oconPCS!=null) 
				{
					if (oconPCS.State != ConnectionState.Closed) 
					{
						oconPCS.Close();
					}
				}
			}
		}
		
		/// <summary>
		/// select step ,type,FunctionID, Work CenterID,EffectBeginDate,EffectEndDate from  PRO_WORouting  where WorkOrderDetailID=<<intWorkOrderDetailID>>
		/// and WorkOrderMasterID=<<intWorkOrderMasterID>>
		/// 
		/// </summary>
		public void GetRoutingInfoBaseWODetail(int pintWOMasterID, int pintWODetailID)
		{
		}
		/// <summary>
		/// select Informations  from PRO_WOScheduleDetail where WorkOrderDetailID =<<pintWODetailID >> and  WorkOrderMasterID =<<pintWOMasterID >>
		/// </summary>
		public DataSet List(int pintWOID, int pintWODetailID)
		{
			return null;
		}
	}
}
